package New;

import java.util.concurrent.*;

public class CompletableFutureDemo {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(1,20,1L
        , TimeUnit.SECONDS, new LinkedBlockingQueue<>(50));
        CompletableFuture<Void> future1 = CompletableFuture.runAsync(()->{
            System.out.println(Thread.currentThread().getName()+"\t"+"---come in");
        });
        System.out.println(future1.get());
        CompletableFuture<Void> future2 = CompletableFuture.runAsync(() -> {
            System.out.println(Thread.currentThread().getName() + "\t" + "----come in");

        }, threadPoolExecutor);
        System.out.println(future2.get());
        CompletableFuture<Integer> future3 = CompletableFuture.supplyAsync(() -> {
            System.out.println(Thread.currentThread().getName() + "\t" + "----come in");
            return 11;
        });
        System.out.println(future3.get());
        CompletableFuture<Integer> future4 = CompletableFuture.supplyAsync(() -> {
            System.out.println(Thread.currentThread().getName() + "\t" + "---come in");
            return 22;
        }, threadPoolExecutor);
        System.out.println(future4.get());
        threadPoolExecutor.shutdown();
    }
}
